package com.xqb.modules.controller.study;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.StdInteractionReply;
import com.xqb.modules.domain.vo.InteractionReplyVo;
import com.xqb.modules.service.IStdInteractionReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 互动问题的回答或评论Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/study/interaction_reply")
public class StdInteractionReplyController extends BaseController
{
    @Autowired
    private IStdInteractionReplyService stdInteractionReplyService;

    /**
     * 查询互动问题的回答或评论列表
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_reply:list')")
    @GetMapping("/list")
    public TableDataInfo list(StdInteractionReply stdInteractionReply)
    {
        startPage();
        List<StdInteractionReply> list = stdInteractionReplyService.selectStdInteractionReplyList(stdInteractionReply);
        return getDataTable(list);
    }

    /**
     * 导出互动问题的回答或评论列表
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_reply:export')")
    @Log(title = "互动问题的回答或评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StdInteractionReply stdInteractionReply)
    {
        List<StdInteractionReply> list = stdInteractionReplyService.selectStdInteractionReplyList(stdInteractionReply);
        ExcelUtil<StdInteractionReply> util = new ExcelUtil<StdInteractionReply>(StdInteractionReply.class);
        util.exportExcel(response, list, "互动问题的回答或评论数据");
    }

    /**
     * 获取互动问题的回答或评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_reply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stdInteractionReplyService.selectStdInteractionReplyById(id));
    }

    /**
     * 新增互动问题的回答或评论
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_reply:add')")
    @Log(title = "互动问题的回答或评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StdInteractionReply stdInteractionReply)
    {
        return toAjax(stdInteractionReplyService.insertStdInteractionReply(stdInteractionReply));
    }

    /**
     * 修改互动问题的回答或评论
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_reply:edit')")
    @Log(title = "互动问题的回答或评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StdInteractionReply stdInteractionReply)
    {
        return toAjax(stdInteractionReplyService.updateStdInteractionReply(stdInteractionReply));
    }

    /**
     * 删除互动问题的回答或评论
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_reply:remove')")
    @Log(title = "互动问题的回答或评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stdInteractionReplyService.deleteStdInteractionReplyByIds(ids));
    }

    /**
     * 查询互动问题的回答
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_reply:list')")
    @GetMapping("/answerList")
    public TableDataInfo answerList(StdInteractionReply stdInteractionReply)
    {
        startPage();
        List<InteractionReplyVo> list = stdInteractionReplyService.selectStdInteractionReplyAnswerList(stdInteractionReply);
        return getDataTable(list);
    }
    /**
     * 查询回答的回复
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_reply:list')")
    @GetMapping("/replyList")
    public TableDataInfo replyList(StdInteractionReply stdInteractionReply)
    {
        List<InteractionReplyVo> list = stdInteractionReplyService.selectStdInteractionReplyReplyList(stdInteractionReply);
        return getDataTable(list);
    }
    /**
     * 点赞或者取消点赞评论或回复
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_reply:edit')")
    @PutMapping("/likes")
    public AjaxResult likes(@RequestBody Long id)
    {
        return success(stdInteractionReplyService.updateStdInteractionReplyLike(id));
    }
   
}
